import { defineStore } from 'pinia';
import { useStorage } from '@vueuse/core';

export const useTenderStore = defineStore('tender', () => {
  // 持久化核心步骤和数据
  const activeStep = useStorage<number>('tender-active-step', 0);
  const tenderTitle = useStorage<string>('tender-title', '');
  const pageCount = useStorage<number>('tender-page-count', 0);
  const wordCount = useStorage<number>('tender-word-count', 0);
  const projectOverview = useStorage<string>('tender-project-overview', '');
  const enableR1Thinking = useStorage<boolean>('tender-enable-r1', true);
  const uploadMode = useStorage<'file'|'paste'>('tender-upload-mode', 'file');
  const textStyleOption = useStorage<string>('tender-text-style', 'technical');
  const tenderType = useStorage<string>('tender-type', 'government');
  const contentMode = useStorage<boolean>('tender-content-mode', false);
  const generatedChapters = useStorage<any[]>('tender-generated-chapters', []);
  const directoryGenerated = useStorage<boolean>('tender-directory-generated', false);
  const showDirectoryOptions = useStorage<boolean>('tender-show-directory-options', false);
  const isEditingSelectedPlan = useStorage<boolean>('tender-is-editing-selected-plan', false);
  const biddoc = useStorage<any>('tender-biddoc', {});
  const directoryOptions = useStorage<any[]>('tender-directory-options', []);
  const activeContentTab = useStorage<string>('tender-active-content-tab', 'content');
  const formattedChapters = useStorage<any[]>('tender-formatted-chapters', []);
  const totalWordPage= useStorage<any>('tender-total-word-page', {});
  const selectedOutlineId= useStorage<any>('tender-selected-outline-id', null);
  const scorePoints= useStorage<any[]>('tender-score-points', []);



  function reset() {
    activeStep.value = 0;
    tenderTitle.value = '';
    pageCount.value = 0;
    wordCount.value = 0;
    projectOverview.value = '';
    enableR1Thinking.value = true;
    uploadMode.value = 'file';
    textStyleOption.value = 'technical';
    tenderType.value = 'government';
    contentMode.value = false;
    generatedChapters.value = [];
    directoryGenerated.value = false;
    showDirectoryOptions.value = false;
    isEditingSelectedPlan.value = false;
    directoryOptions.value = [];
    biddoc.value = {};
    formattedChapters.value = [];
    activeContentTab.value = 'content';
    totalWordPage.value={}
    selectedOutlineId.value=null
    scorePoints.value=[]
  }

  return {
    activeStep,
    tenderTitle,
    pageCount,
    wordCount,
    projectOverview,
    enableR1Thinking,
    uploadMode,
    textStyleOption,
    tenderType,
    contentMode,
    generatedChapters,
    directoryGenerated,
    showDirectoryOptions,
    isEditingSelectedPlan,
    directoryOptions,
    biddoc,
    activeContentTab,
    formattedChapters,
    totalWordPage,
    selectedOutlineId,
    scorePoints,
    reset
  };
}); 